﻿@{
    ViewBag.Title = "卸货地点";
    Layout = "~/Views/Shared/_ManufactureList.cshtml";
}
<script type="text/javascript">
    var currRowId = 0;
    var ifEdit = false;
    var number = "";
    var status = "I";
    $(function () {
        initControl();
        gridList();
        hideEditDiv();
    });
    function hideEditDiv() {
        ifEdit = false;
        $('#eidt_div').hide();
        $('.ui-jqgrid-bdiv').height($('.ui-jqgrid-bdiv').height() + 38);
        if ($('#btn_add').hasClass("disabled")) {
            $('#btn_add').removeClass("disabled");
        }
        if (currRowId > 0) {
            if ($('#btn_edit').hasClass("disabled")) {
                $('#btn_edit').removeClass("disabled");
            }
        }
        $('#btn_list').show();
    }
    function showEditDiv() {
        ifEdit = true;
        $('#eidt_div').show();
        $('.ui-jqgrid-bdiv').height($('.ui-jqgrid-bdiv').height() - 38);
        if (!$('#btn_add').hasClass("disabled")) {
            $('#btn_add').addClass("disabled");
        }
        if (!$('#btn_edit').hasClass("disabled")) {
            $('#btn_edit').addClass("disabled");
        }
        $('#btn_list').hide();
    }
    function initControl() {
        initBindSelect("#form1");
        initBindSelect("#form2");
    }
    function gridList() {
        var $gridList = $("#gridList");
        $gridList.dataGrid({
            url: "/MainData/UserCenter/GetUserCenterJson",
            height: $(window).height() - 156,
            colModel: [
                { label: '用户中心编码', name: 'UserCenter', width: 90, align: 'center', sortable: false },
                { label: '用户中心名称', name: 'UserCenterName', width: 180, align: 'left', sortable: false },
                { label: '备注说明', name: 'Fdesc', width: 480, align: 'left', sortable: false },
                { label: '创建人员', name: 'FCreateBy', width: 80, align: 'left', sortable: false },
                { label: '创建日期', name: 'FCreateDate', width: 80, align: 'center', sortable: false },
                { label: '创建时间', name: 'FCreateTime', width: 80, align: 'center', sortable: false },
                { label: '更改人员', name: 'FUpdateBy', width: 80, align: 'left', sortable: false },
                { label: '更改日期', name: 'FUpdateDate', width: 80, align: 'center', sortable: false },
                { label: '更改时间', name: 'FUpdateTime', width: 80, align: 'center', sortable: false },
                { label: '', name: 'UserCenterID', width: 80, align: 'center', hidden: true }
            ],
            pager: "#gridPager",
            sortname: 'UserCenter asc',
            viewrecords: true,  //是否显示行数
            rownumWidth: 40,
            gridComplete: function () {

            },
            loadComplete: function () {
                var rowDatas = $gridList.jqGrid("getRowData");
                var length = rowDatas.length + 1;
                if (length > 0) {
                    if (currRowId == 0) {
                        currRowId = 1;
                    } else if (currRowId > length) {
                        currRowId = length;
                    }
                }
                if (currRowId > 0) {
                    $gridList.jqGrid('setSelection', currRowId);
                    var $grid = $('#gview_gridList .ui-jqgrid-bdiv');
                    $grid.setScrollTop(length, currRowId);
                }
            },
            onSelectRow: function (rowid) {
                currRowId = rowid;
                $('#btn_remove').removeClass("disabled");
                var rowData = $gridList.jqGrid('getRowData', rowid);
                number = rowData.UserCenterID;

                if (currRowId > 0) {
                    if ($('#btn_edit').hasClass("disabled")) {
                        $('#btn_edit').removeClass("disabled");
                    }
                }

                emptyDataById("#eidt_div");
                if (status == "U") {
                    setDataByJson("#eidt_div", rowData);
                    initBindSelect("#eidt_div");
                }

            },
            beforeSelectRow: function (rowid, e) {
                //if (ifEdit) {
                //    return false;
                //}
            },
            onPaging: function (page_btn) {
                currRowId = 1;
            }
        });
        $gridList.jqGrid('setLabel', 0, '序号', 'rowNumberHeaderStyle');
        $gridList.jqGrid('setFrozenColumns');
        $("#btn_search").click(function () {
            reloadGrid();
        });
    }
    function reloadGrid(currNumber) {
        currNumber = currNumber || '';
        var currPage = 1;
        if (currNumber != "") {
            //var data = $("#form1").formSerialize();
            var data = {};
            var page = $('#gridList').getGridParam('page'); // current page
            var rows = $('#gridList').getGridParam('rowNum'); // rows
            var sidx = $('#gridList').getGridParam('sortname'); // sidx
            var sord = $('#gridList').getGridParam('sortorder'); // sord
            data["sidx"] = sidx;
            data["sord"] = sord;
            data["rows"] = rows;
            data["currNumber"] = currNumber;
            $.ajaxSetup({ async: false });
            $.getJSON("/MainData/UserCenter/GetUserCenterSortJson", data, function (result) {
                currPage = result.currPage;
                currRowId = result.currIndex;
            });
            $.ajaxSetup({ async: true });
            emptyDataById("#form1");
            $("#gridList").jqGrid('setGridParam', {
                page: currPage,
            }).trigger('reloadGrid');
        } else {
            $("#gridList").jqGrid('setGridParam', {
                postData: $("#form1").formSerialize(),
            }).trigger('reloadGrid');
        }
    }
    function btn_add() {
        status = 'I';
        emptyDataById("#eidt_div");
        initBindSelect("#eidt_div");
        showEditDiv();
        NumberDisabled();
    }
    function btn_edit() {
        status = 'U';
        var rowData = $("#gridList").jqGrid('getRowData', currRowId);
        //alert(rowData.UnitID);
        emptyDataById("#eidt_div");
        setDataByJson("#eidt_div", rowData);
        initBindSelect("#eidt_div");
        showEditDiv();
        NumberDisabled();
    }
    function btn_remove() {
        var rowData = $("#gridList").jqGrid('getRowData', currRowId);
        $.modalConfirm("注：您确定要【删除】该条数据吗？", function (r) {
            if (r) {
                $.submitForm({
                    url: "/MainData/UserCenter/SubmitUserCenterForm?status=D",
                    param: { keyValue: rowData.UserCenterID },
                    success: function () {
                        emptyDataById("#form2");
                        reloadGrid();
                    }
                })
            }
        });
    }
    function btn_ok() {
        submitForm();
    }
    function submitForm() {
        if (!$('#form2').formValid()) {
            return false;
        }
        $.submitForm({
            url: "/MainData/UserCenter/SubmitUserCenterForm?status=" + status + "&keyValue=" + number,
            param: $("#form2").formSerialize(),
            success: function (result) {
                if (result.data != '') {
                    reloadGrid(result.data);
                } else {
                    reloadGrid();
                }
                hideEditDiv();
            }
        })
    }
    function btn_cancel() {
        hideEditDiv();
    }
    function NumberDisabled() {
        if (status == 'I') {
            $('#UserCenter').prop("readonly", false);
        } else if (status == 'U') {
            $('#UserCenter').prop("readonly", true);
        }
    }
    function btn_export() {
        var url = "/Common/ExcelExport?" + init_sql();
        location.href = url;
    }
    function init_sql() {
        var tablename = "ZSJ_D2_UserCenter";
        var condition = "UseUnit='@FriendStar.Code.Configs.GetValue("UseUnit")'";
        var cols = [];
        //获取列字段
        var colModel = $("#gridList").jqGrid('getGridParam', 'colModel');
        for (var i = 0; i < colModel.length; i++) {
            var columnHidden = colModel[i].hidden;
            var columnName = colModel[i].name;
            var columnLabel = colModel[i].label;
            if (columnHidden == false && columnName != "rn" && columnName != "") {
                if (columnLabel != '') {
                    cols.push(columnName + ' [' + columnLabel + ']');
                } else {
                    cols.push(columnName);
                }
            }
        }
        if ($('#UserCenter1').val() != '') {
            condition += " AND UserCenter LIKE '%" + $('#UserCenter1').val() + "%'";
        }
        if ($('#UnitFullName').val() != '') {
            condition += " AND UserCenterName LIKE '%" + $('#UserCenterName1').val() + "%'";
        }
        var sql = "SELECT " + cols.join(',') + " FROM " + tablename + " WHERE " + condition + " ORDER BY UserCenter ASC";
        return "sql=" + sql;
    }
</script>
<div id="layout" style="height: 100%; width: 100%;">
    <form id="form1">
        <div style="padding: 12px 0 5px 0; padding-left: 15px; border-bottom: 1px solid #ccc;" class="line-table input-width-140">
            <div class="btn-group" style="margin-top:-9px;">
                用户中心编码<br /><input id="UserCenter1" name="UserCenter" type="text" class="form-control" /> &nbsp;
            </div>
            <div class="btn-group input-width-185" style="margin-top:-9px;">
                用户中心名称<br /><input id="UserCenterName1" name="UserCenterName" type="text" class="form-control" /> &nbsp;
            </div>
            <div class="btn-group" style="">
                <a id="btn_search" class="btn btn-primary center-block" onclick=""><span class="glyphicon glyphicon-search"></span> 检索</a>
            </div>
            <div id="btn_list" class="btn-group" style="float:right;padding-right:10px;">
                <a id="" class="btn btn-primary center-block" onclick="$.reload()"><span class="glyphicon glyphicon-refresh"></span> 刷新</a>
                <a id="btn_add" class="btn btn-primary center-block" onclick="btn_add()"><span class="glyphicon glyphicon-plus"></span> 新增</a>
                <a id="btn_remove" class="btn btn-primary center-block disabled" onclick="btn_remove()"><span class="glyphicon glyphicon-trash"></span> 删除</a>
                <a id="btn_edit" class="btn btn-primary center-block disabled" onclick="btn_edit()"><span class="glyphicon glyphicon-edit"></span> 修改</a>
                <a id="btn_export" class="btn btn-primary center-block" onclick="btn_export()"><span class="glyphicon glyphicon-download"></span> 导出</a>
            </div>
        </div>
    </form>
    <form id="form2">
        <table id="eidt_div" class="form" style="margin:3px 0;">
            <tr>
                <th class="formTitle" style="width:90px;">用户中心编码</th>
                <td class="formValue" style="width:150px;">
                    <input id="UserCenter" name="UserCenter" type="text" class="form-control required" maxlength="2" />
                    <input id="UserCenterID" name="UserCenterID" type="hidden" />
                </td>
                <th class="formTitle" style="width:90px;">用户中心名称</th>
                <td class="formValue" style="width:210px;">
                    <input id="UserCenterName" name="UserCenterName" type="text" class="form-control required" />
                </td>
                <th class="formTitle" style="width:70px;">备注说明</th>
                <td class="formValue" style="width:210px;">
                    <input id="Fdesc" name="Fdesc" type="text" class="form-control" />
                </td>
                <td class="formValue">
                    &nbsp;&nbsp;&nbsp;
                    <div class="btn-group" style="margin-top:2px;">
                        <a id="btn_ok" class="btn btn-primary center-block btn-1" onclick="btn_ok()"><span class="glyphicon glyphicon-ok"></span> 输入</a>
                    </div>
                    &nbsp;&nbsp;&nbsp;
                    <div class="btn-group" style="margin-top:2px;">
                        <a id="btn_cancel" class="btn btn-primary center-block btn-1" onclick="btn_cancel()"><span class="glyphicon glyphicon-remove"></span> 取消</a>
                    </div>
                </td>
            </tr>
        </table>
    </form>
    <div style="">
        <table id="gridList"></table>
        <div id="gridPager"></div>
    </div>
</div>

